<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>留学生管理系统</title>  
        <link rel="stylesheet" href="${path}/css/admin2.css">
        <style>
            #tea-modal-1, #tea-modal-2{
                margin: 12% auto;
                padding: 10px;
                width: 500px;
            }
        </style>
        <script>
            var _current_item = "#adminteamanage";
        </script>
        <script type="text/javascript" src="${path}/js/jquery.min.js"></script>
    </head>
    <body>
        <!--header-->
        <div id="above-mask">
            <div class="fileupload pannel hide" id="fileupload-pannel">
                <div class="close-container">
                    <a class="close" onclick="hide('#above-mask, #mask, #fileupload-pannel');">×</a>
                </div>
                <form action="${path}/adminteamanage/fileUpload" method="post" enctype="multipart/form-data" name="fileForm">
                    <div style="margin-top: 30px;"> 上传文件：（支持Excel 97-2003 工作簿 .xls格式文件）</div>
                    <input id="fileCover" class="left" readonly="readonly" placeholder="导入excel文件" type="text" style="width: 280px; height: 22px;">
                    <button onclick="$('#uploadFile').click();return false;" style="background: #aaa">浏览文件</button>
                    <input type="file" name="uploadFile" required="required" id="uploadFile" style="display:none" onchange="$('#fileCover').val($(this).val());">
                    <div>
                        <button type="submit" style="display: block; margin: 0 auto;">提交</button> 
                    </div>
                </form>
            </div>
            <div class="pannel hide" id="tea-modal-1">
                <div class="am-modal-dialog">
                    <div class="close-container">
                        <a class="close" onclick="hide('#mask, #above-mask, #tea-modal-1')">&times;</a>
                    </div>
                    <form action="${path}/adminteamanage/submit" method="post">
                        <table id="teachertable1">
                            <tr>
                                <td>工号</td>
                                <td> <input type="text" placeholder="必填" name="teacherInfo.tNo" required="required"></td>
                            </tr>
                            <tr>
                                <td>姓名</td>
                                <td><input type="text" placeholder="必填" name="teacherInfo.tName" required="required"></td>
                            </tr>
                            <tr>
                                <td>学院</td>
                                <td>
                                    <#if allcollegeCodeName?exists>
                                    <select name="teacherInfo.collegeCode" id="collegeCode">
                                        <#list allcollegeCodeName as cc>
                                        <option value="${cc.collegeCode}">${cc.collegeCode}-${cc.collegeName}</option>
                                        </#list>
                                    </select>
                                    </#if>
                                </td>
                            </tr>
                            <tr>
                                <td>职称</td>
                                <td> <input type="text" placeholder="必填" name="teacherInfo.title" required="required"></td>
                            </tr>
                            <tr><td colspan="2"><button type="submit">确定</button></td></tr>
                        </table>	
                    </form>	
                </div>
            </div>
            <div class="pannel hide" id="tea-modal-2">
                <div class="close-container">
                    <a class="close" onclick="hide('#mask, #above-mask, #tea-modal-2')">&times;</a>
                </div>
                <form action="${path}/adminteamanage/update" method="post">
                    <table id="teachertable2">
                        <tr>
                            <td>工号</td>
                            <td></td>
                        </tr>
                        <tr>
                            <td>姓名</td>
                            <td> <input type="text" placeholder="必填" name="teacherInfo.tName" id="tName" value="" required="required"></td>
                        </tr>
                        <tr>
                            <td>学院</td>
                            <td> 
                                <#if allcollegeCodeName?exists>
                                <select name="teacherInfo.collegeCode" id="collegeCode2">
                                    <#list allcollegeCodeName as cc>
                                    <option value="${cc.collegeCode}">${cc.collegeCode}-${cc.collegeName}</option>
                                    </#list>
                                </select>
                                </#if>
                            </td>
                        </tr>
                        <tr>
                            <td>职称</td>
                            <td> <input type="text" placeholder="必填" name="teacherInfo.title"  id="title" value="" required="required"></td>
                        </tr>				
                        <tr>
                            <td colspan="2">
                                <input type="hidden" name="teacherInfo.id" id="id" value="">
                                <input type="hidden" name="teacherInfo.tNo" id="tNo" value="">
                                <button type="button" onclick="ajaxupdate();hide('#mask, #above-mask, #tea-modal-2')">确定</button>
                            </td>
                        </tr>
                    </table>		
                </form>
            </div>
        </div>
        <div id="mask"></div>
        <div id="header"></div>
        <div id="main">
            <div id="side-menu"></div>
            <div id="container">
                <div id="inner-border">
                        <select id="keywords" name="keywords">
                            <option value="all">全部</option>
                            <#if allcollegeCodeName?exists>
                            <#list allcollegeCodeName as c>
                            <option value="${c.collegeCode}">${c.collegeCode}-${c.collegeName}</option>
                            </#list>
                            </#if>
                        </select>   
                        <button type="button" onclick="ajaxscreen()">筛选</button>
                    	
                    <button onclick="window.location.href = '${path}/adminteamanage/fileDownload'">模板下载</button>
                    <button onclick="show('#mask, #above-mask, #fileupload-pannel')">批量导入</button>
                    <button onclick="window.location.href='${path}/teainfExport/exportExcel'">批量导出</button>
                    <button onclick="show('#mask, #above-mask, #tea-modal-1')">新增教师</button>
                    	
                    <form action="${path}/adminteamanage/batch" method="post" name="myForm">
                        <input type="hidden" name="checkboxValue" id="checkboxValue">
                        <div id="error" style="display:none">${error!}</div>  
                        <input type="hidden" name="action" value="re"> 
                        <table class="table table-bordered" id="ttable">
                            <thead>
                                <tr>
                                    <th>&nbsp;&nbsp;&nbsp;</th>
                                    <th>工号</th>
                                    <th>姓名</th>
                                    <th>学院名称</th>
                                    <th>职称</th>
                                    <th>操作<script type="text/javascript">
                            function ajaxscreen() {
                                $.ajax({
                                    type: "post",
                                    url: '${path}/adminteamanage/ajaxscreen',
                                    data: {
                                        keywords: $('#keywords').val(),
                                    },
                                    datatype: "json",
                                    success: function (data) {
                                   // alert(JSON.stringify(data));
                                    $('#ttable').dataTable().fnClearTable();
                                    $.each(data,function(num,data){
                                    $('#ttable').dataTable().fnAddData(['<input type="checkbox" value="' + data["id"] + '" name="teaCheckbox" id="teaCheckbox" >', data["tNo"], data["tName"], data["collegeName"], data["title"], '<button class="edit" name="editBtn" onclick="edit(this);show(\'#mask, #above-mask, #tea-modal-2\');return false;">编辑</button>']);
                                                    
                                    })
                                        //alert("success");
                                       /*  for (var i = 0; i < data.length; i++)
                                            // alert(data[i]["tNo"]);

                                            $(document).ready(function () {
                                                $('#ttable').dataTable().fnClearTable();


                                                for (var i = 0; i < data.length; i++) {
                                                    $('#ttable').dataTable().fnAddData(['<input type="checkbox" value="' + data[i]["id"] + '" name="teaCheckbox" id="teaCheckbox" >', data[i]["tNo"], data[i]["tName"], data[i]["collegeCode"], data[i]["title"], '<button name="editBtn" onclick="edit(this);show(\'#mask, #above-mask, #tea-modal-2\');return false;">编辑</button>']);
                                                    var id = data[i]["id"];
                                                    //alert(id);
                                                    var ot = $('#ttable').dataTable();
                                                }
                                            }); */
                                    }
                                });
                            }
        </script></th>
                                </tr>
                            </thead>
                            <tbody>
                                <#if teacherInfo?exists>
                                <#list teacherInfo as ti> 
                                <tr>
                                    <td><input type="checkbox" value="${ti.id}" name="teaCheckbox" id="teaCheckbox"></td>
                                    <td>${ti.tNo}</td>
                                    <td>${ti.tName}</td>
                                    <td>${ti.collegeName}</td>
                                    <td>${ti.title}</td>
                                    <td><button class="edit" onclick="edit(this);show('#mask, #above-mask, #tea-modal-2');return false;">编辑</button></td>
                                </tr>
                                </#list>
                                </#if>
                            </tbody>
                        </table>
                        <button class="delete" type="submit" onclick="getParam('ttable', 'checkboxValue');submitFun('delete');">删除</button>
                        <button type="submit" onclick="getParam('ttable', 'checkboxValue');submitFun('re');">重置密码</button>
                    </form>
                </div>
            </div>
        </div>
                <div id="footer"></div>
        <script type="text/javascript" src="${path}/js/admin-main-appearance.js"></script>

        <!-- DataTables JavaScript -->
        <script src="${path}/bower_components/datatables/media/js/jquery.dataTables.min.js"></script>
        <script src="${path}/bower_components/datatables-plugins/api/fnGetHiddenNodes.js"></script>
        <script src="${path}/bower_components/datatables-plugins/api/fnGetTd.js"></script>
        <script src="${path}/bower_components/datatables-plugins/api/fnGetTds.js"></script>
        <script src="${path}/bower_components/datatables-plugins/api/fnGetColumnData.js"></script>
        <script src="${path}/bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.min.js"></script>
        <script src="${path}/js/linkPage.js"></script>
        
        <script type="text/javascript">
            var row;
            function edit(node) {
                var tr1 = node.parentNode.parentNode;
                document.getElementById('teachertable2').rows[0].cells[1].innerHTML = tr1.cells[1].innerHTML;
                document.getElementById('tName').value = tr1.cells[2].innerHTML;
                
                document.getElementById('title').value = tr1.cells[4].innerHTML;
                document.getElementById('id').value = tr1.cells[0].children[0].value;
                document.getElementById('tNo').value = tr1.cells[1].innerHTML;
                row = tr1.rowIndex;
                return row;

            }
            function ajaxupdate() {
                $.ajax({
                    type: "post",
                    url: '${path}/adminteamanage/ajaxupdate',
                    data: {
                        tName: $('#tName').val(),
                        collegeCode: $('#collegeCode2').val(),
                        title: $('#title').val(),
                        id: $('#id').val(),
                        tNo: $('#tNo').val(),
                    },
                    datatype: "json",
                    success: function (data) {
                   // alert(JSON.stringify(data));
                        document.getElementById('ttable').rows[row].cells[2].innerHTML = data.teacherInfo[0]["tName"];
                        document.getElementById('ttable').rows[row].cells[3].innerHTML = data.teacherInfo[0]["collegeName"];
                        document.getElementById('ttable').rows[row].cells[4].innerHTML = data.teacherInfo[0]["title"];
                        alert(data.error);
                    }
                });
            }
        </script>
        <script type="text/javascript">
            $(document).ready(function () {
                $('#ttable').DataTable({
                    responsive: true,
                    ordering: false,
                    searching: true,
                    "bLengthChange": false,
                    "bRetrieve": true,
                    "bFilter": true//过滤功能
                });
            });
        </script>  
        <script type="text/javascript">
            function submitFun(act)
            {
                myForm.action.value = act;
                myForm.submit();
            }
        </script>
        <script type="text/javascript">
            $(document).ready(function () {
                if ($("#error").html() != "") {
                    Alert($("#error").html());
                }
                //alert($("#error").html());}
            });
        </script> 
        <script>
            //自动关闭提示框  
            function Alert(str) {
                alert(str);
            }
        </script>
    </body>
</html>
